import tensorflow as tf


class Metrics:

    def __init__(self, y_true, y_pred):
        self.confusion_matrix = tf.math.confusion_matrix(y_true, y_pred)
        self.TP = self.confusion_matrix[1][1]
        self.FP = self.confusion_matrix[0][1]
        self.FN = self.confusion_matrix[1][0]
        self.TN = self.confusion_matrix[0][0]

    def accuracy(self):
        return (self.TN + self.TP)/(self.TN + self.TP + self.FP + self.FN)

    def specificity(self):
        return self.TN/(self.TN + self.FP)

    def sensitivity(self):
        return self.TP/(self.TP + self.FN)

    def print_metrics(self):
        print("acc:%f,spe:%f,sen:%f"%(self.accuracy(), self.specificity(), self.sensitivity()))
